package com.ynny.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.ynny.fallback.SentinelFallback;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sentinel")
public class SentinelController {

    @RequestMapping("/rt")
    //fallback(降级) 方法+实现降级方法+降级类
    @SentinelResource(value = "getRtResource", fallback = "rtFallback",
            fallbackClass = SentinelFallback.class)

    public String getRt() {

        // 模拟耗时
        try {
            Thread.sleep(1000);
        }catch(InterruptedException e){

            throw new RuntimeException(e);
        }

        return "进入RT";
    }

    //异常比例
    @RequestMapping("/getEorRate")
    @SentinelResource(value = "getEorRateResource", fallback = "ycFallback",
            fallbackClass = SentinelFallback.class)
    public String getEorRate() {
        int i= 5/0;
        return "进入异常比例";
    }

    //异常数
    @RequestMapping("/getEorNum")
    @SentinelResource(value = "getEorNumResource", fallback = "ysNumFallback",
            fallbackClass = SentinelFallback.class)
    public String getEorNum() {
        int i= 5/0;
        return "进入异常数";
    }

}